1 : <?php
2 :
3 : /*--------------------------------------------------------------------------+
4 : This file is part of eStudy
5 : externaltools/classes/class.toolinfo.inc.php
6 : - Modulgruppe: ExternalTools
7 : - Beschreibung:
8 : - Version: 1.0 13/10/05
9 : - Autor(en): Christian Gerhardt <case42@gmx.net>
10 : +---------------------------------------------------------------------------+
11 : This program is free software; you can redistribute it and/or
12 : modify it under the terms of the GNU General Public License
13 : as published by the Free Software Foundation; either version 2
14 : of the License, or any later version.
15 : +---------------------------------------------------------------------------+
16 : This program is distributed in the hope that it will be useful,
17 : but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : GNU General Public License for more details.
20 : You should have received a copy of the GNU General Public License
21 : along with this program; if not, write to the Free Software
22 : Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 : +--------------------------------------------------------------------------*/
24 : /**
25 : * Diese Datei enthällt die Klasse ToolInfo
26 : * @package eStudy.ExternalTools
27 : * @version 1.0 13/10/05
28 : * @author Christian Gerhardt <case42@gmx.net>
29 : */
30 : /**
31 : * Wird <b>nach</b> dem hinzufügen des users ausgeführt
32 : */
33 1 : define("OPTIONS_EVENT_LOGON", 1);
34 : /**
35 : * Wird <b>vor</b> dem anzeigen der Seite ausgeführt.
36 : */
37 1 : define("OPTIONS_EVENT_SHOW_PAGE", 2);
38 : /**
39 : *
40 : */
41 1 : class ToolInfo {
42 : public $toolName = "Tool Name";
43 : public $toolID = null;
44 : public $logondata = null;
45 : public $toolDB = null;
46 : public $userData = null;
47 : public $userLogonData = null;
48 : public $image = null;
49 : public $toolOptions = null;
50 :
51 : public function ToolInfo($image) {
52 0 : $this->image = $image;
53 0 : }
54 :
55 : public function getName() {
56 0 : return $this->toolName;
57 : }
58 :
59 : public function logon($userID) {
60 0 : $this->getLogonData();
61 0 : $this->connectToDB();
62 0 : $this->userData = $this->getUserData($userID);
63 0 : $this->getUserLoginData($userID);
64 0 : if (!$this->checkForUser()) {
65 0 : if (is_null($this->userLogonData)) {
66 0 : return false;
67 : } else {
68 0 : $this->insertNewUser();
69 0 : $this->optionsHandler(OPTIONS_EVENT_LOGON);
70 : }
71 0 : }
72 0 : return true;
73 : }
74 :
75 : public function getLogonData() {
76 0 : global $db, $settings;
77 0 : if ($this->toolID != null) {
78 0 : $query = "SELECT dbUser, dbPassword, dbName, dbUrl FROM %set_tooldata WHERE ID = '%s'";
79 0 : $query = sprintf($query, $settings['dbPrefix'], trim($this->toolID));
80 0 : $result = $db->get_row($query, ARRAY_A);
81 0 : $this->logondata = $result;
82 0 : }
83 0 : }
84 :
85 : public function connectToDB() {
86 0 : if (!$this->logondata) {
87 0 : $this->getLogonData();
88 0 : }
89 0 : if ($this->logondata) {
90 0 : $this->toolDB = new ezdb($this->logondata['dbUser'], $this->logondata['dbPassword'], $this->logondata['dbName'], $this->logondata['dbUrl']);
91 0 : }
92 0 : }
93 :
94 : public function getUserData($userID) {
95 0 : global $db, $EZSQL_ERROR, $settings;
96 0 : $query = "SELECT * FROM %suser WHERE ID='%s'";
97 0 : $query = sprintf($query, $settings['dbPrefix'], $userID);
98 0 : return $db->get_row($query, ARRAY_A);
99 : }
100 :
101 : /**
102 : * Holt die login daten des benutzers aus der datenbank.
103 : * Diese daten sind dafür bestimmt um im eingeführten tool als
104 : * zugangsdaten eingesetzt zu werden.
105 : */
106 : public function getUserLoginData($userID) {
107 0 : global $db, $EZSQL_ERROR, $settings;
108 0 : if (is_null($this->userLogonData)) {
109 0 : $query = "SELECT * FROM %set_userlogindata WHERE userID='%s'";
110 0 : $query = sprintf($query, $settings['dbPrefix'], $userID);
111 0 : $this->userLogonData = $db->get_row($query, ARRAY_A);
112 0 : }
113 0 : return $this->userLogonData;
114 : }
115 :
116 : public function update($oldLogin, $newLogin, $password) {
117 0 : $this->getLogonData();
118 0 : $this->connectToDB();
119 0 : $this->userData = $this->getUserData($_SESSION['userid']);
120 0 : $this->userLogonData = $this->getUserLoginData($this->userData['ID']);
121 0 : return $this->updateLogin($oldLogin, $newLogin, $password);
122 : }
123 :
124 : public function getImageLink($name) {
125 0 : if ($this->image != null) {
126 0 : $string = "<img src='%sexternaltools/images/%s' alt='%s' title='%s' />";
127 0 : return sprintf($string, PATH_TO_ROOT, $this->image, $name, $name);
128 : } else {
129 0 : return $name;
130 : }
131 : }
132 :
133 : public function checkForUser() {
134 0 : return true;
135 : }
136 :
137 : public function insertNewUser() {
138 0 : }
139 :
140 : public function removeUser($userID) {
141 0 : }
142 :
143 : public function updateLogin($lodLogin, $newLogin, $password) {
144 0 : return null;
145 : }
146 :
147 : public function showOptionsDialog($hiddenVars) {
148 0 : return true;
149 : }
150 :
151 : public function handleToolOptions($event) {
152 0 : $this->getLogonData();
153 0 : $this->connectToDB();
154 0 : $this->userData = $this->getUserData($_SESSION['userid']);
155 0 : $this->userLogonData = $this->getUserLoginData($this->userData['ID']);
156 0 : $this->optionsHandler($event);
157 0 : }
158 :
159 : public function optionsHandler($event) {
160 0 : }
161 :
162 : public function getToolOptions() {
163 0 : return $this->toolOptions;
164 : }
165 :
166 : public function setToolOptions($options) {
167 0 : $this->toolOptions = $options;
168 0 : }
169 : }
170 : ?>
|